package com.drcoffee.drcoffeemall.service.impl;

import com.drcoffee.drcoffeemall.entry.Attachment;
import com.drcoffee.drcoffeemall.entry.Result;
import com.drcoffee.drcoffeemall.entry.User;
import com.drcoffee.drcoffeemall.entry.Video;
import com.drcoffee.drcoffeemall.mapper.VideoMapper;
import com.drcoffee.drcoffeemall.service.VideoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public class VideoServiceImpl implements VideoService {

    @Autowired
    VideoMapper videoMapper;

    @Override
    public Result getVideo(Map<String, Object> parMap) {
        try {
            PageHelper.startPage((Integer) parMap.get("currPage"), (Integer) parMap.get("pageSize"));
            String search = (String) parMap.get("search");
            Integer machine_id = (Integer) parMap.get("machine_id");
            PageInfo<Video> videoPage = new PageInfo<>(videoMapper.getVideo(machine_id, '%' + search + '%'));
            return new Result(1, "SUCCESS", "", videoPage);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(-1, "ERROR", e.getMessage(), null);
        }
    }
}
